package net.yxsoft.task;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.cron4j.ITask;
import net.yxsoft.chainmaker.InitClient;
import net.yxsoft.kit.Helper;
import net.yxsoft.service.EvidenceService;
import net.yxsoft.service.OrderService;

import java.util.List;

public class BlockTasks implements ITask {

    private static Helper helper = Helper.me;

    @Override
    public void run() {

        System.out.println("开始获取区块链数据");

        //取所有智能合约信息
        List<Record> records = Db.find("SELECT distinct attrib_06, attrib_33 FROM fn_form_data WHERE ATTRIB_01='8a43bd9e876449af9e4c98587a24dc53' ");

        for (int i = 0; i < records.size(); i++) {
            String scontactname = records.get(i).get("attrib_06");

            try {
                OrderService.getAllOrdersToDb(InitClient.chainClient, scontactname);
                OrderService.getAllStatesToDb(InitClient.chainClient, scontactname);
                EvidenceService.getAllEvidencesToDb(InitClient.chainClient, scontactname);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }

        }
    }


    @Override
    public void stop() {

    }
}
